package com.example.democonsumer.controller;

import com.example.democonsumer.remote.HelloFeignClient;
import com.example.democonsumer.remote.HelloController;
import com.myrpc.annotation.MyRpcRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/get")
public class GetController {
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    HelloFeignClient helloFeignClient;

    @MyRpcRemote
    HelloController helloController;
    @GetMapping("/restTemplate")
    public String getProducerResponseByRestTemplat(){
        String url = "http://demo-producer/hello";
        String response = restTemplate.getForObject(url, String.class);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) + " The response is :" + response;
    }

    @GetMapping("/feign")
    public String getProducerResponseByFeign(){
        String response = helloFeignClient.getRequest();
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) + " The response is :" + response;
    }

    @GetMapping("/myRpc")
    public String getProducerResponseByMyRpc(){
        String response = helloController.getRequest();
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) + " The response is :" + response;

    }

}
